<template>
	<view class="content">
		<view>
			<view class="top">
				<img src="/static/order/cdz.png" alt="">
				<view class="title">正在充电</view>
				<view class="canshu">
					<view>费用预估(元)
						<view class="text">
							<text>
								{{orderInfo.expectAmount}}元
							</text>
						</view>
					</view>
					<view>已使用时长
						<view class="text">
							<text>
								{{$util.convertSecondsToTime(orderInfo.totalSeconds)}}
							</text>
						</view>
					</view>

				</view>
			</view>
			<view class="info">
				<view class="item">
					<view class="info">
						<view class="title">{{orderInfo.cabinet.merchant.name}}</view>
						<text>充电柜编号：{{orderInfo.cabinet.cabinetNo}}</text>
						<text>订单开始时间：{{orderInfo.beginAt}}</text>
						<text>商户地址：{{orderInfo.cabinet.merchant.address}}</text>
						<text>价格规则：{{orderInfo.cabinet.merchant.priceTemplate.info}}</text>
					</view>

				</view>
			</view>
			<view class="jieshu" @tap="finishOrder">
				结束充电
			</view>
		</view>
	</view>
</template>

<script>
	import BingCountup from "@/components/bing-countup/bing-countup.vue"

	import {
		mapState,
		mapActions
	} from 'vuex'
	let that
	export default {
		components: {
			'bing-countup': BingCountup
		},
		data() {
			return {
				orderInfo: {},
			}
		},
		onShow() {
			this.getdetail()
		},
		mounted() {
			that = this
		},
		methods: {
			getdetail() {
				this.$http_api.ordersNoFinish({
				}).then((res) => {
					console.log("ordersNoFinish:",res)
					that.orderInfo = res;
				})
			},
			//结束订单
			finishOrder() {
				uni.showModal({
					title: '结束订单',
					content: '请确认是否结束充电',
					success: function(res) {
						if (res.confirm) {
							that.$http_api.ordersFinishOrder({
							}).then((res) => {
								console.log("ordersFinishOrder:",res)
								uni.redirectTo({
									url: '/pages/orders/order-pay'
								});
							})
						}
					}
				})

			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;
		padding: 0 3%;
		box-sizing: border-box;
	}

	.top {
		padding-top: 80rpx;
		margin-bottom: 40rpx;
		text-align: center;
		padding-bottom: 40rpx;
		border-bottom: 1px solid #ccc;

		img {
			width: 200rpx;
			height: 200rpx;
			margin-bottom: 40rpx;
			border: 5px solid #23BF61;
			padding: 40rpx;
			border-radius: 100%;
		}

		.title {
			margin-bottom: 50rpx;
			font-weight: bold;
		}

		.date {
			font-size: 28rpx;
			color: #666;
			margin-bottom: 60rpx;
		}

		.canshu {
			display: flex;
			justify-content: space-between;
			width: 100%;
			margin: 0 auto;

			view {
				font-size: 26rpx;
				color: #666;

				text {
					display: block;
					font-size: 32rpx;
					font-weight: bold;
					color: #333;
					margin-top: 10rpx;
				}

			}

			.time {
				display: flex;
			}
		}

	}

	.item {
		background: #fff;
		padding: 20rpx;
		margin-bottom: 40rpx;
		border-radius: 10rpx;

		.info {
			background: url("/static/order/cd.png") no-repeat right;
			background-size: 28px;
			background-position-y: 0;

			.title {
				font-size: 31rpx;
				font-weight: 600;
				margin-bottom: 20rpx;
			}

			text {
				font-size: 28rpx;
				display: block;
				color: #666;
				margin-top: 20rpx;
			}
		}
	}

	.jieshu {
		width: 300rpx;
		padding: 20rpx 0;
		border-radius: 40rpx;
		background: #23BF61;
		color: #fff;
		text-align: center;
		margin: 90rpx auto 0;
	}
</style>